# #Lagos download script
LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
## Warning in LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path()): LAGOSNE data for this version already exists on the local machine.
## Re-download if neccessary using the 'overwrite` argument.'
#Load in lagos
lagos <- lagosne_load()
## Warning in (function (version = NULL, fpath = NA) : LAGOSNE version unspecified,
## loading version: 1.087.3
#Grab the lake centroid info
lake_centers <- lagos$locus
#Look at the column names
#names(lake_centers)
#Look at the structure
#str(lake_centers)
#View the full dataset
#View(lake_centers %>% slice(1:100))
spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'),
crs=4326) %>%
st_transform(2163)
#Subset for plotting
subset_spatial <- spatial_lakes %>%
slice(1:100)
subset_baser <- spatial_lakes[1:100,]
#Dynamic mapviewer
mapview(subset_spatial)
states <- us_states()
#Plot all the states to check if they loaded
mapview(states)
minnesota <- states %>%
filter(name == 'Minnesota') %>%
st_transform(2163)
#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]
#Plotting the first 1000 lakes
minnesota_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
Iowa_Illinois <- states %>%
filter(name %in% c('Iowa', 'Illinois')) %>%
st_transform(2163)
mapview(Iowa_Illinois)
combined? How does this compare to Minnesota?
Iowa_Illinois_lakes <- spatial_lakes[Iowa_Illinois,]
nrow(Iowa_Illinois_lakes)
## [1] 16466
nrow(minnesota_lakes)
## [1] 29038
# Make Iowa's lakes size data
Iowa <- states %>%
filter(name=='Iowa') %>%
st_transform(2163)
Iowa_lakes <- spatial_lakes[Iowa,]
Iowa_lakes_size <- data.frame(Iowa_lakes$lake_area_ha) %>%
rename(Lake_Size=1) %>%
mutate(State='Iowa')
# Make Minnesota's lakes size data
minnesota_lakes_size <- data.frame(minnesota_lakes$lake_area_ha) %>%
rename(Lake_Size=1) %>%
mutate(State='Minnesota')
# Bind two data frames
Compare_lake_size <- rbind(Iowa_lakes_size, minnesota_lakes_size)
ggplot(Compare_lake_size, aes(x=Lake_Size, fill=State)) +
xlim(1,200) +
xlab('Lake Size(ha)') +
geom_histogram(bins = 300, alpha=0.6, position = "identity") +
theme_few() +
scale_color_few() +
theme(legend.position=c(0.8,0.8))
## Warning: Removed 703 rows containing non-finite values (stat_bin).
## Warning: Removed 4 rows containing missing values (geom_bar).
by lake area in hectares
Iowa_Illinois_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
natural lakes vary in size in these three states?
Compare_lake_length <- rbind(minnesota_lakes, Iowa_Illinois_lakes)
Compare_lake_length %>%
arrange(-lake_perim_meters) %>%
slice(1:1000) %>%
mapview(., zcol='lake_perim_meters')